package logic

import (
	"context"
	"goods_srv/goods"
	"goods_srv/internal/svc"
	"goods_srv/work/model"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsSearchLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsSearchLogic {
	return &GoodsSearchLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsSearchLogic) GoodsSearch(in *goods.GoodsSearchReq) (*goods.GoodsSearchResp, error) {

	var goods2 model.Goods2

	search, err := goods2.Search(in.GoodsName)
	if err != nil {
		return nil, err
	}

	return &goods.GoodsSearchResp{
		Id:             int64(search.ID),
		GoodsName:      search.GoodsName,
		GoodsPrice:     int64(search.GoodsPrice),
		GoodsStock:     search.GoodsStock,
		GoodsUrl:       search.GoodsUrl,
		GoodsIntroduce: search.GoodsIntroduce,
		GoodsShing:     int64(search.GoodsShing),
		GoodsStatus:    int64(search.GoodsStatus),
		GoodsSort:      int64(search.GoodsSort),
	}, nil
}
